package Day35.map;

import java.util.*;

public class HashMapDemo1 {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<String,String>(){{
            put("key1","val1");
            put("key2","val2");
            put("key3","val3");
            put("key4","val4");
            put("key5","val5");
        }};
        //获得所有的key
        Set<String> keySet = map.keySet();
        //使用keySet遍历Map集合
        Iterator<String> it = keySet.iterator();
        while(it.hasNext()){
            String key = it.next();
            String value = map.get(key);
            System.out.println(key+"<---->"+value);
        }

        //获得所有的value
        Collection<String> values = map.values();
        for(String val : values){
            System.out.println(val);
        }


        System.out.println("******************");
        for (Map.Entry<String,String> entry : map.entrySet()){
            System.out.println(entry.getKey()+"<--->"+entry.getValue());
        }

    }
}
